#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct Node{
	int id;
	int score;
};
int n,m;
vector<Node> a;
bool cmp(Node a,Node b){
	return a.id<b.id;
}
int main(){
	int id,score;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n+m;i++){
		scanf("%d%d",&id,&score);
		Node n;
		n.id=id;
		n.score=score;
		a.push_back(n);
	}
	sort(a.begin(),a.end(),cmp);
	for(int i=0;i<n+m;i++){
		printf("%d %d\n",a[i].id,a[i].score);
	}
	return 0;
} 
